


package com.primecodegen.common.ProjectProperties;

/**
 *----------------------------------------------------------
 *----------------------------------------------------------
 * @author Mohammad Awwad
 * Version: v0.0
 * contact: mhmdawwad@gmail.com
 *-----------------------------------------------------------
 *-----------------------------------------------------------
 */

import java.sql.*;
import java.util.*;
import com.primecodegen.common.base.*;
import com.primecodegen.util.*;
import java.util.logging.*;

public class ProjectPropertiesDAO extends BaseDAO {

       protected static String TblName = "Project_Properties";
       protected java.sql.Connection projectPropertiesConn;
       protected static final Logger logger = Logger.getLogger (ProjectPropertiesDAO.class.getName ());

       public ProjectPropertiesDAO () {
              super ();
       }

       public int insert ( IBaseTable projectPropertiesTable ) throws Exception {


              final boolean isConnSupplied = ( projectPropertiesConn != null );
              ProjectPropertiesTable newRecord = ( ProjectPropertiesTable ) projectPropertiesTable;
              int insertValue = ComConstants.UNREALISTIC_INT;
              Connection con = null;
              PreparedStatement PrepSt = null;
              String sInsertSQL = null;
              StringBuffer sbSQL = new StringBuffer ();

              if ( projectPropertiesTable == null ) {
                     throw new Exception ("DAOException in ProjectPropertiesDAO class :projectPropertiesTable is Null");
              }
              sInsertSQL = "INSERT INTO " + ProjectPropertiesDAO.TblName + " (";
              try {
                     con = isConnSupplied ? projectPropertiesConn : ResourceManager.getConnection ();

                     String sComma = "";
                     int iColCount = 0;
		

								 if (!util.isEmpty(newRecord.getID())) {
								iColCount = iColCount + 1;
								sbSQL.append(sComma).append(ProjectPropertiesDBCols.ID);
								sComma = ",";
									}
					
								 if (!util.isEmpty(newRecord.getMainPrjID())) {
								iColCount = iColCount + 1;
								sbSQL.append(sComma).append(ProjectPropertiesDBCols.MAINPRJID);
								sComma = ",";
									}
					
								 if (!util.isEmpty(newRecord.getCode())) {
								iColCount = iColCount + 1;
								sbSQL.append(sComma).append(ProjectPropertiesDBCols.CODE);
								sComma = ",";
									}
					
								 if (!util.isEmpty(newRecord.getType())) {
								iColCount = iColCount + 1;
								sbSQL.append(sComma).append(ProjectPropertiesDBCols.TYPE);
								sComma = ",";
									}
					
								 if (!util.isEmpty(newRecord.getDescr())) {
								iColCount = iColCount + 1;
								sbSQL.append(sComma).append(ProjectPropertiesDBCols.DESCR);
								sComma = ",";
									}
					 
			
		     sbSQL.append (") VALUES (");
                     sComma = "";
                     for ( int i = 0 ; i < iColCount ; i++ ) {
                            sbSQL.append (sComma).append ("?");
                            sComma = ",";
                     }
                     sbSQL.append (");");

                     sInsertSQL = sInsertSQL + sbSQL.toString ();

                     PrepSt = con.prepareStatement (sInsertSQL ,
                             Statement.RETURN_GENERATED_KEYS);
                     int i = 1;



			 						      if (!util.isEmpty(newRecord.getID())) {
			 							PrepSt.setInt(i++, newRecord.getID());
			 						    }
			 			
			 						      if (!util.isEmpty(newRecord.getMainPrjID())) {
			 							PrepSt.setInt(i++, newRecord.getMainPrjID());
			 						    }
			 			
			 					   if (!util.isEmpty(newRecord.getCode().trim())) {
			 							PrepSt.setString(i++, newRecord.getCode().trim());
			 						    }
			 			
			 					   if (!util.isEmpty(newRecord.getType().trim())) {
			 							PrepSt.setString(i++, newRecord.getType().trim());
			 						    }
			 			
			 					   if (!util.isEmpty(newRecord.getDescr().trim())) {
			 							PrepSt.setString(i++, newRecord.getDescr().trim());
			 						    }
			 			 

		     insertValue = PrepSt.executeUpdate ();
                     ResultSet rsIDJustInserted = PrepSt.getGeneratedKeys ();
                     if ( rsIDJustInserted.next () ) {
                            insertValue = rsIDJustInserted.getInt (1);
                     }



              } catch ( SQLException sqlEx ) {
                     logger.log (Level.WARNING , "SQLException in ProjectPropertiesDAO.insert method Message: {0}" , sqlEx.getMessage ());
                     throw new Exception ("SQLException in ProjectPropertiesDAO.insert method");
              } catch ( Exception e ) {
                     logger.log (Level.WARNING, "Exception in ProjectPropertiesDAO.insert method Message: {0}", e.getMessage ());
                     throw new Exception ("Exception in ProjectPropertiesDAO.insert method");
              } finally {
                     ResourceManager.close (PrepSt);
                     if ( !isConnSupplied ) {
                            ResourceManager.close (con);
                     }
              }

              return insertValue;
       }

       public int deleteByID ( int IDPar ) throws Exception {

              final boolean isConnSupplied = ( projectPropertiesConn != null );
              int ID = ( int ) IDPar;
              Connection con = null;
              PreparedStatement stmnt = null;
              int noOfRowsDeleted = ComConstants.UNREALISTIC_INT;
              String deleteSQL = "DELETE FROM " + ProjectPropertiesDAO.TblName + " WHERE " + ProjectPropertiesDBCols.ID + " = ?";
              try {
                     con = isConnSupplied ? projectPropertiesConn : ResourceManager.getConnection ();
                     stmnt = con.prepareStatement (deleteSQL);
                     stmnt.setInt (1, ID);

                     noOfRowsDeleted = stmnt.executeUpdate ();



              } catch ( SQLException sqlEx ) {
                     logger.log (Level.WARNING, "SQLException in ProjectPropertiesDAO.DeleteByID method Message: {0}", sqlEx.getMessage ());
                     throw new Exception ("SQLException in ProjectPropertiesDAO.deleteByID method"
                             + sqlEx.getMessage ());
              } catch ( Exception e ) {
                     logger.log (Level.WARNING, "Exception in ProjectPropertiesDAO.DeleteByID method Message: {0}", e.getMessage ());
                     throw new Exception ("Exception in ProjectPropertiesDAO.deleteByID method"
                             + e.getMessage ());
              } finally {
                     if ( !isConnSupplied ) {
                            ResourceManager.close (con);
                     }
              }
              return noOfRowsDeleted;
       }

       public int updateByCriterion ( IBaseTable projectPropertiesSrchCriterionDTOPar ,
               IBaseTable updatedRecordPar ) throws Exception {

              final boolean isConnSupplied = ( projectPropertiesConn != null );
              ProjectPropertiesTable projectPropertiesSrchCriterionDTO = ( ProjectPropertiesTable ) projectPropertiesSrchCriterionDTOPar;
              ProjectPropertiesTable updatedRecord = ( ProjectPropertiesTable ) updatedRecordPar;
              int iNoOfRecordsUpdated = -1;
              Connection con = null;
              PreparedStatement stmnt = null;
              try {

                     con = isConnSupplied ? projectPropertiesConn : ResourceManager.getConnection ();
                     StringBuffer sbUpdateSQLStmnt = new StringBuffer ();
                     String sComma = "";
                     sbUpdateSQLStmnt.append ("UPDATE ").append (ProjectPropertiesDAO.TblName).append (" SET ");



		 		          if ( !util.isEmpty (updatedRecord.getID ()) ) {
		                             sbUpdateSQLStmnt
		                                     .append (sComma)
		                                     .append (ProjectPropertiesDBCols.ID + " = ")
		                                     .append ("?");
		                             sComma = ",";
		                      }
		 		
		 		          if ( !util.isEmpty (updatedRecord.getMainPrjID ()) ) {
		                             sbUpdateSQLStmnt
		                                     .append (sComma)
		                                     .append (ProjectPropertiesDBCols.MAINPRJID + " = ")
		                                     .append ("?");
		                             sComma = ",";
		                      }
		 		
		 		          if ( !util.isEmpty (updatedRecord.getCode ()) ) {
		                             sbUpdateSQLStmnt
		                                     .append (sComma)
		                                     .append (ProjectPropertiesDBCols.CODE + " = ")
		                                     .append ("?");
		                             sComma = ",";
		                      }
		 		
		 		          if ( !util.isEmpty (updatedRecord.getType ()) ) {
		                             sbUpdateSQLStmnt
		                                     .append (sComma)
		                                     .append (ProjectPropertiesDBCols.TYPE + " = ")
		                                     .append ("?");
		                             sComma = ",";
		                      }
		 		
		 		          if ( !util.isEmpty (updatedRecord.getDescr ()) ) {
		                             sbUpdateSQLStmnt
		                                     .append (sComma)
		                                     .append (ProjectPropertiesDBCols.DESCR + " = ")
		                                     .append ("?");
		                             sComma = ",";
		                      }
		 		 
		
                     sbUpdateSQLStmnt.append (getUpdateWhereClause (projectPropertiesSrchCriterionDTO));

                     stmnt=con.prepareStatement (sbUpdateSQLStmnt.toString ());
		     int i=1;

             		if ( !util.isEmpty (updatedRecord.getID ()) ) {
                                     stmnt.setInt (i++, updatedRecord.getID ());
                                  }
             		
             		if ( !util.isEmpty (updatedRecord.getMainPrjID ()) ) {
                                     stmnt.setInt (i++, updatedRecord.getMainPrjID ());
                                  }
             		
             		if ( !util.isEmpty (updatedRecord.getCode ()) ) {
                                     stmnt.setString (i++, updatedRecord.getCode ());
                                  }
             		
             		if ( !util.isEmpty (updatedRecord.getType ()) ) {
                                     stmnt.setString (i++, updatedRecord.getType ());
                                  }
             		
             		if ( !util.isEmpty (updatedRecord.getDescr ()) ) {
                                     stmnt.setString (i++, updatedRecord.getDescr ());
                                  }
             		 
                   

                     iNoOfRecordsUpdated = stmnt.executeUpdate ();

              } catch ( Exception e ) {
                     logger.log (Level.WARNING, "Exception in ProjectPropertiesDAO.updateByCriterion method Message: {0}", e.getMessage ());
                     throw new Exception (
                             "Exception in ProjectPropertiesDAO.updateByCriterion method ");
              } finally {
                     if ( !isConnSupplied ) {
                            ResourceManager.close (con);
                     }
              }

              return iNoOfRecordsUpdated;
       }

      public int updateByID ( IBaseTable newRecordPar ) throws Exception {
              ProjectPropertiesTable newRecord = ( ProjectPropertiesTable ) newRecordPar;
              if ( newRecord != null ) {
                     ProjectPropertiesTable contentsCategorySrchCriterionDTO = new ProjectPropertiesTable ();
                     contentsCategorySrchCriterionDTO.setID (newRecord.getID ());
                     return this.updateByCriterion (contentsCategorySrchCriterionDTO , newRecord);
              } else {
                     logger.log (Level.WARNING , "Exception in method ProjectPropertiesDAO.update.newRecord passed is null.");
                     throw new Exception (
                             "Exception in method ProjectPropertiesDAO.update.newRecord passed is null.");
              }
       }
       private String getUpdateWhereClause ( ProjectPropertiesTable projectPropertiesSrchCriterionDTO ) {
              String sWhere = "";
              if ( projectPropertiesSrchCriterionDTO.getID () != ComConstants.UNREALISTIC_INT ) {
                     sWhere = " WHERE ID = " + projectPropertiesSrchCriterionDTO.getID ();
              }
              return sWhere;
       }

 

       public IBaseTable getByID ( int ID ) throws Exception {

              if ( !util.isEmpty (ID) ) {
                     ProjectPropertiesTable projectPropertiesSrchCriterionDTO = new ProjectPropertiesTable ();
                     projectPropertiesSrchCriterionDTO.setID (ID);
                     projectPropertiesSrchCriterionDTO.setFilter (true);
                     ArrayList<ProjectPropertiesTable> projectPropertiesTables = this.getByCriterionOrderedBy (
                             projectPropertiesSrchCriterionDTO , null);
                     ProjectPropertiesTable projectPropertiesTable = null;
                     if ( projectPropertiesTables != null ) {
                            Iterator<ProjectPropertiesTable> it = projectPropertiesTables.iterator ();
                            while ( it.hasNext () ) {
                                   projectPropertiesTable = ( ProjectPropertiesTable ) it.next ();
                            }
                     }

                     return projectPropertiesTable;
              } else {
                     logger.log (Level.WARNING , "Exception in method ProjectPropertiesDAO.getByID.ID passed is unrealistic.");
                     throw new Exception (
                             "Exception in method ProjectPropertiesDAO.getByID.ID passed is unrealistic.");
              }
       }


           public boolean deleteMainProjectIsSafe(int mainProjectID) throws Exception {
        ArrayList<ProjectPropertiesTable> projectPropertiesTables = new ArrayList<ProjectPropertiesTable>();
        if (!util.isEmpty(mainProjectID)) {
            ProjectPropertiesTable projectPropertiesSrchCriterionDTO = new ProjectPropertiesTable();
            projectPropertiesSrchCriterionDTO.setMainPrjID(mainProjectID);
            projectPropertiesSrchCriterionDTO.setFilter(true);
            projectPropertiesTables = this.getByCriterionOrderedBy(projectPropertiesSrchCriterionDTO, null);

            if (projectPropertiesTables.size()>0) {
                return false;//Delete is SAFE, Group Empty
            } else {
                return true;
            }

        } else {
            logger.log(Level.WARNING, "Exception in method ProjectPropertiesDAO.getByID.ID passed is unrealistic.");
            throw new Exception(
                    "Exception in method ProjectPropertiesDAO.getByID.ID passed is unrealistic.");
        }
    }

       public ArrayList<ProjectPropertiesTable> getByCriterionOrderedBy (
               IBaseTable projectPropertiesSrchCriterionDTOPar , ColToOrderBy colToOrderBy )
               throws Exception {


              final boolean isConnSupplied = ( projectPropertiesConn != null );
              ProjectPropertiesTable projectPropertiesSrchCriterionDTO = ( ProjectPropertiesTable ) projectPropertiesSrchCriterionDTOPar;
              Connection con = null;
              PreparedStatement stmnt = null;
              ResultSet rs = null;

              String sWhereClause = "";

              String sOrderBy = "";
              if ( colToOrderBy != null && colToOrderBy.Name != null ) {
                     sOrderBy = this.getOrderBy (colToOrderBy);
              }
              if ( projectPropertiesSrchCriterionDTO != null && projectPropertiesSrchCriterionDTO.isFilter ()) {
                     try {
                            sWhereClause = this.getRetrieveWhereClause (projectPropertiesSrchCriterionDTO);
                     } catch ( Exception e ) {
                            System.out.println ("getByCriterionOrderedBy.Exception..");
                            throw new Exception (" ProjectProperties.getByCriterionOrderedBy.Exception:  "+ e.getMessage ());
                     }

                     if ( sWhereClause != null && !sWhereClause.trim ().equalsIgnoreCase ("") ) {
                            sWhereClause = " WHERE " + sWhereClause;
                     }
              }
              ArrayList<ProjectPropertiesTable> projectPropertiesTables = new ArrayList<ProjectPropertiesTable> ();

              try {
                     con = isConnSupplied ? projectPropertiesConn : ResourceManager.getConnection ();

                     String sSelectSQL = "SELECT * FROM   " + TblName;
//                       StringBuilder sSelectSQL = new StringBuilder();
//                        sSelectSQL.append("SELECT ").append(" roles.ID ").append(" AS ").append(RolesDBCols.ID).append(", roles.Code ").append(" AS ").append(RolesDBCols.CODE).append(", roles.Name ").append(" AS ").append(RolesDBCols.NAME).append(", roles.Description ").append(" AS ").append(RolesDBCols.DESCRIPTION).append(", roles.Details ").append(" AS ").append(RolesDBCols.DETAILS).append(", roles.IsActive ").append(" AS ").append(RolesDBCols.ISACTIVE).append(", roles.IsVisible ").append(" AS ").append(RolesDBCols.ISVISIBLE).append(", roles_group.ID ").append(" AS ").append(RolesDBCols.ROLEGROUPID).append(", roles_group.GroupName ").append(" AS ").append(RolesDBCols.ROLEGROUPNAME).append(" FROM ").append(" roles ").append("INNER JOIN roles_group ON (roles.RolesGroupID = roles_group.ID)");

                     stmnt = con.prepareStatement (sSelectSQL + sWhereClause + sOrderBy);
			

			

                     if ( projectPropertiesSrchCriterionDTO != null && projectPropertiesSrchCriterionDTO.isFilter ()) {
                            int colCount = 1;
				

						  if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.getID ()) ) {
			                                   stmnt.setInt (colCount++ , projectPropertiesSrchCriterionDTO.getID ());
			                            }
						
						  if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.getMainPrjID ()) ) {
			                                   stmnt.setInt (colCount++ , projectPropertiesSrchCriterionDTO.getMainPrjID ());
			                            }
						
						  if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.getCode ()) ) {
			                                   stmnt.setString (colCount++ , projectPropertiesSrchCriterionDTO.getCode ());
			                            }
						
						  if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.getType ()) ) {
			                                   stmnt.setString (colCount++ , projectPropertiesSrchCriterionDTO.getType ());
			                            }
						
						  if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.getDescr ()) ) {
			                                   stmnt.setString (colCount++ , projectPropertiesSrchCriterionDTO.getDescr ());
			                            }
						 
		  }

                     rs = stmnt.executeQuery ();
                     ProjectPropertiesTable projectPropertiesTable = null;

                     while ( rs.next () ) {
                            projectPropertiesTable = new ProjectPropertiesTable ();


						  
							 projectPropertiesTable.setID (rs.getInt (ProjectPropertiesDBCols.ID));
						
						  
							 projectPropertiesTable.setMainPrjID (rs.getInt (ProjectPropertiesDBCols.MAINPRJID));
						
						  
							projectPropertiesTable.setCode (util.removeNullFrom (rs.getString  (ProjectPropertiesDBCols.CODE)));
						
						  
							projectPropertiesTable.setType (util.removeNullFrom (rs.getString  (ProjectPropertiesDBCols.TYPE)));
						
						  
							projectPropertiesTable.setDescr (util.removeNullFrom (rs.getString  (ProjectPropertiesDBCols.DESCR)));
						 
                  
			projectPropertiesTables.add (projectPropertiesTable);
                        projectPropertiesTable = null;
                     }

              } catch ( SQLException sqlEx ) {
                     logger.log (Level.WARNING, "SQLException in ProjectPropertiesDAO.insert method Message: {0}", sqlEx.getMessage ());
                     throw new Exception (
                             "SQLException in method:ProjectPropertiesDAO.getByCriterionOrderedBy"
                             + sqlEx.getMessage ());
              } catch ( Exception e ) {
                     logger.log (Level.WARNING, "Exception in ProjectPropertiesDAO.insert method Message: {0}", e.getMessage ());
                     throw new Exception (
                             "Exception in method:ProjectPropertiesDAO.getByCriterionOrderedBy"
                             + e.getMessage ());
              } finally {
                     if ( !isConnSupplied ) {
                            ResourceManager.close (con);
                     }
              }
              return projectPropertiesTables;
       }

       private String getRetrieveWhereClause ( ProjectPropertiesTable projectPropertiesSrchCriterionDTO )
               throws Exception {


              StringBuffer sbWhereClause = new StringBuffer ();
              String sAnd = "";
              boolean bPrevColExistsInWhereClause = false;
              boolean bAtLeastOneFieldExists = false;

              if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.getID ()) ) {
                     bAtLeastOneFieldExists = true;
                     sbWhereClause.append (" ID =").append (" ? ");
                     bPrevColExistsInWhereClause = true;
              }

              if ( projectPropertiesSrchCriterionDTO.Opr != null ) {
		


		                                        if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.Opr.getIDOpr ().trim ()) && !util.isEmpty (projectPropertiesSrchCriterionDTO.getID ()) ) {
		                                            bAtLeastOneFieldExists = true;
		                                            if ( bPrevColExistsInWhereClause ) {
		                                                   sAnd = " AND ";
		                                            } else {
		                                                   sAnd = "";
		                                            }
		                                           sbWhereClause.append (sAnd).append (" " + ProjectPropertiesDBCols.ID + "  ").append (projectPropertiesSrchCriterionDTO.Opr.getIDOpr ().trim ()).append ("?");
		                                           bPrevColExistsInWhereClause = true;
		                                     }

				
		                                        if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.Opr.getMainPrjIDOpr ().trim ()) && !util.isEmpty (projectPropertiesSrchCriterionDTO.getMainPrjID ()) ) {
		                                            bAtLeastOneFieldExists = true;
		                                            if ( bPrevColExistsInWhereClause ) {
		                                                   sAnd = " AND ";
		                                            } else {
		                                                   sAnd = "";
		                                            }
		                                           sbWhereClause.append (sAnd).append (" " + ProjectPropertiesDBCols.MAINPRJID + "  ").append (projectPropertiesSrchCriterionDTO.Opr.getMainPrjIDOpr ().trim ()).append ("?");
		                                           bPrevColExistsInWhereClause = true;
		                                     }

				
		                                 if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.Opr.getCodeOpr ().trim ()) && !util.isEmpty (projectPropertiesSrchCriterionDTO.getCode ().trim ()) ) {
		                                            bAtLeastOneFieldExists = true;
		                                            if ( bPrevColExistsInWhereClause ) {
		                                                   sAnd = " AND ";
		                                            } else {
		                                                   sAnd = "";
		                                            }
		                                            if ( projectPropertiesSrchCriterionDTO.Opr.getCodeOpr ().trim ().equalsIgnoreCase ("LIKE") ) {
		                                                   sbWhereClause.append (sAnd).append (" " + ProjectPropertiesDBCols.CODE + " LIKE").append (" ? ");
		                                            } else {
		                                                   sbWhereClause.append (sAnd).append (" " + ProjectPropertiesDBCols.CODE + "  ").append (projectPropertiesSrchCriterionDTO.Opr.getCodeOpr ().trim ()).append ("?");
		                                            }
		                                            bPrevColExistsInWhereClause = true;
		                                     }

				
		                                 if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.Opr.getTypeOpr ().trim ()) && !util.isEmpty (projectPropertiesSrchCriterionDTO.getType ().trim ()) ) {
		                                            bAtLeastOneFieldExists = true;
		                                            if ( bPrevColExistsInWhereClause ) {
		                                                   sAnd = " AND ";
		                                            } else {
		                                                   sAnd = "";
		                                            }
		                                            if ( projectPropertiesSrchCriterionDTO.Opr.getTypeOpr ().trim ().equalsIgnoreCase ("LIKE") ) {
		                                                   sbWhereClause.append (sAnd).append (" " + ProjectPropertiesDBCols.TYPE + " LIKE").append (" ? ");
		                                            } else {
		                                                   sbWhereClause.append (sAnd).append (" " + ProjectPropertiesDBCols.TYPE + "  ").append (projectPropertiesSrchCriterionDTO.Opr.getTypeOpr ().trim ()).append ("?");
		                                            }
		                                            bPrevColExistsInWhereClause = true;
		                                     }

				
		                                 if ( !util.isEmpty (projectPropertiesSrchCriterionDTO.Opr.getDescrOpr ().trim ()) && !util.isEmpty (projectPropertiesSrchCriterionDTO.getDescr ().trim ()) ) {
		                                            bAtLeastOneFieldExists = true;
		                                            if ( bPrevColExistsInWhereClause ) {
		                                                   sAnd = " AND ";
		                                            } else {
		                                                   sAnd = "";
		                                            }
		                                            if ( projectPropertiesSrchCriterionDTO.Opr.getDescrOpr ().trim ().equalsIgnoreCase ("LIKE") ) {
		                                                   sbWhereClause.append (sAnd).append (" " + ProjectPropertiesDBCols.DESCR + " LIKE").append (" ? ");
		                                            } else {
		                                                   sbWhereClause.append (sAnd).append (" " + ProjectPropertiesDBCols.DESCR + "  ").append (projectPropertiesSrchCriterionDTO.Opr.getDescrOpr ().trim ()).append ("?");
		                                            }
		                                            bPrevColExistsInWhereClause = true;
		                                     }

				


              }

              if ( sbWhereClause.toString ().trim ().length () <= 0 ) {
                     logger.log (Level.WARNING , "getRetrieveWhereClause Cannot return Null  ");
                     throw new Exception ("getRetrieveWhereClause Cannot return Null  ");
              } else {
                     return sbWhereClause.toString ().trim ();
              }
       }

       private String getOrderBy ( ColToOrderBy colToOrderBy ) {
              String sOrderBy = " Order By ";

              sOrderBy = sOrderBy + colToOrderBy.Name;

              if ( colToOrderBy.OrderType != null ) {
                     sOrderBy = sOrderBy + " " + colToOrderBy.OrderType;
              }
              return sOrderBy;
       }

       public int deleteByCriterion ( IBaseTable recordsToDeleteCritPar )
               throws Exception {

              final boolean isConnSupplied = ( projectPropertiesConn != null );
              ProjectPropertiesTable recordsToDeleteCrit = ( ProjectPropertiesTable ) recordsToDeleteCritPar;
              int iNoOfRecordsDeleted = -1;
              Connection con = null;
              PreparedStatement stmnt = null;

              StringBuffer sbDeleteSQLStmnt = new StringBuffer ();
              sbDeleteSQLStmnt
                      .append ("DELETE from ")
                      .append (ProjectPropertiesDAO.TblName)
                      .append (" WHERE ");

              String sWhereClause = "";
              if ( recordsToDeleteCrit != null &&  recordsToDeleteCrit.isFilter ()) {
                     try {
                            sWhereClause = this.getRetrieveWhereClause (recordsToDeleteCrit);
                     } catch ( Exception e ) {
                            System.out.println ("getByCriterionOrderedBy.Exception..");
                            throw new Exception (" ProjectProperties.deleteByCriterion.Exception:  "
                                    + e.getMessage ());
                     }

                     if ( sWhereClause != null
                             && !sWhereClause.trim ().equalsIgnoreCase ("") ) {
                            sWhereClause = " WHERE " + sWhereClause;
                     }

                     sbDeleteSQLStmnt.append (sWhereClause);
              }
              try {
                     con = isConnSupplied ? projectPropertiesConn : ResourceManager.getConnection ();
                     stmnt = con.prepareStatement (sbDeleteSQLStmnt.toString ());

                     if ( recordsToDeleteCrit != null &&  recordsToDeleteCrit.isFilter ()) {

                     }
                   //  iNoOfRecordsDeleted = stmnt.executeUpdate ();



                     return iNoOfRecordsDeleted;
              } catch ( SQLException sqlEx ) {
                     logger.log (Level.WARNING, "SQLException in ProjectPropertiesDAO.deleteByCriterion method Message: {0}", sqlEx.getMessage ());
                     throw new Exception (
                             "SQLException in ProjectPropertiesDAO.deleteByCriterion method");
              } catch ( Exception e ) {
                     logger.log (Level.WARNING, "Exception in ProjectPropertiesDAO.deleteByCriterion method Message: {0}", e.getMessage ());
                     throw new Exception (
                             "Exception in ProjectPropertiesDAO.deleteByCriterion method");
              } finally {

                     if ( !isConnSupplied ) {
                            ResourceManager.close (con);
                     }
              }
       }
}
